package com.yuan.SMS.controller;

import com.alibaba.fastjson.JSON;
import com.yuan.SMS.dao.StudentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
@RestController
public class PoliticsCountController {
    @Autowired
    StudentDao politicsCdao;

    @RequestMapping("/politics")
    @CrossOrigin("http://localhost:8080")
    public String politicsCount(String politics){
        System.out.println(politics);
        int i = politicsCdao.getStudentCounts();
        int j = politicsCdao.getStudentCountsByPolitics(politics);
        double perc = j/i;
        HashMap<String, Object> res = new HashMap<>();
        if(i!=0.00){
            res.put("flag","success");
            res.put("data",perc);
        }else{
            res.put("flag","error");
        }
        return JSON.toJSONString(res);
    }
}
